package com.github.tommyettinger.random;

import com.github.tommyettinger.random.ChopRandom;

import java.util.Arrays;

/** Launches the desktop (LWJGL3) application. */
public class OtherLauncher {
	/**
	 * This stops at i=1206704139, which is greater than 2 to the 30. This means all non-negative {@code short} values
	 * for x and y can be given as points here, and get unique int results. The first point this finds that repeats a
	 * hash is (x=7843, y=47809), where y is above {@link Short#MAX_VALUE}.
	 * <br>
	 * In a main method so it can be run from a JAR, outside any IDE for memory reasons.
	 * @param args ignored
	 */
	public static void main(String[] args) {
		final int[] all = new int[1 << 17];
//		final int[] primes =
//				{
//						3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
//						101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
//						197, 199, 211, 223, 227, 229, 233, 239, 241, 251
//				};
//		for (int p0 = 0; p0 < primes.length; p0++) {
//			int m = primes[p0];
//			for (int p1 = p0 + 1; p1 < primes.length; p1++) {
//				int n = primes[p1] << 1;

		//with mask=0xFFFF, use x * 18688 + y * 11085;
		//with mask=0xFFFF, use x * 4447 + y * 5888;
		//with mask=0x3FFFF, use x * 1111 + y * 1536;
		int state = 1;
		ChopRandom r0 = new ChopRandom(1);
		ChopRandom r1 = new ChopRandom(-100);
		for (int q = 0; q < 0x20000; q++) {
//		{
//			int m = state = state * 229 + 0xDE4D & 0x1FFFF;
//			int n = state = state * 229 + 0xDE4D & 0x1FFFF;
			int m = r0.nextInt() & 0xFFFFF, n = r1.nextInt() & 0xFFFFF;
			PER_BIT:
			for (int bits = 20; bits <= 20; bits += 2) {
				int mask = (1 << bits) - 1;
				int i = 0;
				for (; i <= mask; i++) {
					int x = Integer.compress(i, 0xAAAAAAAA);
					int y = Integer.compress(i, 0x55555555);
					//0xC13FA9A902A6328FL 0x91E10DA5C79E7B1DL
					//0xC13FA9A9 0x91E10DA5
//				int idx = (x * 0xC13FA9AD + y * 0x91E10DBF); // primes
//				int idx = (x * 0xC13FA9A9 + y * 0x91E10DA5); // will avoid collisions if load factor is 0.25f or less
//				int idx = (x * 0xC13FA9A9 + y * 0x9E3779BA);
//				int idx = (x * 0xC13FA9A9 ^ y * 0x91E10DA5); // xor, awful
//				int idx = (x * 0xC13FA9A9 + y * 0x9E3779B9);
//				int idx = (x * 0xC13FA9AD + y * 0x9E3779B9);
//					int idx = (x * m + y * n);
					int idx = (x * m ^ y * n);
//					int idx = y + ((x + y) * (x + y + 1) >>> 1); // Cantor pairing function
//					int idx = y + ((x + y) * (x + y + 1) >> 1); // Cantor pairing function
//					int idx = (x >= y ? x * (x + 2) - y : y * y + x); // Rosenberg-Strong pairing function
					idx &= mask;
					int upper = idx >>> 5, lower = idx & 31;
					if (all[upper] == (all[upper] |= 1 << lower)) {
//						if(i >= 0x8000)
//							System.out.println("With " + m + " " + n + ", generated " + i + " pairs before a collision.");
						Arrays.fill(all, 0);
						continue PER_BIT;
					}
//				else if ((i & 0xFFFF) == 0) System.out.println("With " + bits + " bits, completed " + i + " pairs.");
				}

//		for (; i < 0; i++) {
//			int x = Integer.compress(i, 0xAAAAAAAA);
//			int y = Integer.compress(i, 0x55555555);
//			int idx = (x * 0xC13FA9A9 + y * 0x91E10DA5 >>> 1),
//					upper = idx >>> 5, lower = idx & 31;
//			if (all[upper] == (all[upper] |= 1 << lower)) {
//				System.out.println("Generated " + i + " pairs before a collision.");
//				return;
//			} else if ((i & 1023) == 0) System.out.println("Completed " + i + " pairs.");
//		}
				Arrays.fill(all, 0);
				System.out.println(m + " " + n);
//				System.out.println("With " + m + " " + n + ", generated all pairs before any collision!!!");
			}
		}
//		}
	}
//
//	/**
//	 * In a main method so it can be run from a JAR, outside any IDE for memory reasons.
//	 * @param args ignored
//	 */
//	public static void main(String[] args) {
//		final BitSet all = new BitSet(0x1000000);
//		int card = 0;
//		OUTER:
//		for (int x = 0; x < 0x800; x+=64) {
//			System.out.println("Finished row " + x);
//			for (int r = 0; r < 64; r++) {
//				for (int y = 0; y < 0x800; y++) {
//					all.set((x+r) * 0xC13FA9A9 + y * 0x91E10DA5 & 0xFFFFFF);
//					if (card == (card = all.cardinality())) {
//						break OUTER;
//					}
//				}
//			}
//		}
//		System.out.println("Generated " + card + " pairs before a collision.");
//	}

//	private static Lwjgl3Application createApplication() {
//		return new Lwjgl3Application(new DistributorDemo(), getDefaultConfiguration());
//	}
//
//	private static Lwjgl3ApplicationConfiguration getDefaultConfiguration() {
//		Lwjgl3ApplicationConfiguration configuration = new Lwjgl3ApplicationConfiguration();
//		configuration.setTitle("Distributor");
//		configuration.setWindowedMode(DistributorDemo.SCREEN_WIDTH, DistributorDemo.SCREEN_HEIGHT);
//		configuration.setIdleFPS(60);
//		configuration.setForegroundFPS(0);
//		configuration.useVsync(false);
//		configuration.disableAudio(true);
//		configuration.setWindowIcon("libgdx128.png", "libgdx64.png", "libgdx32.png", "libgdx16.png");
//		return configuration;
//	}
}

//// Random 20-bit multiplier pairs for a mask of 0xFFFF, using +

//1001083 259328
//911109 527616
//3 874240
//273115 857344
//1045879 804608
//551168 491933
//295069 454912
//813312 216117
//948992 743995
//1020383 151296
//187135 260864
//928415 354048
//631529 252672
//234233 177408
//815233 839936
//692047 467200
//391595 48896
//146825 570112
//48384 891177
//697088 215019
//583907 516352
//258304 490077
//730719 680704
//335616 319889
//556288 544047
//718907 506112
//145035 347904
//570624 597729
//23003 183552
//835840 861377
//374791 967936
//138195 582912
//810752 415635
//940299 562432
//775815 694016
//624207 309504
//446208 537369
//250624 189943
//101120 112759
//471847 332544
//255431 38144
//185600 973369
//285029 902912
//56064 112685
//908544 986573
//710037 1046784
//545745 128256
//96000 561565
//491041 954112
//630528 595245
//200851 1022720
//475392 844689
//934144 891991
//713472 1044557
//976031 531200
//690143 545024
//736641 786176
//393984 905157
//757547 151808
//220075 338688
//474637 512256
//728507 920832
//394013 717568
//158003 247040
//171915 61184
//636355 1047808
//906079 73472
//845105 737536
//304896 117705
//772352 655493
//35359 1001728
//264787 158464
//1032960 1007775
//53517 724224
//52097 901376
//93440 876399
//714496 880349
//26880 827897
//488192 520959
//489051 851200
//16128 209177
//298697 976640
//648960 281285
//197755 330496
//457163 945920
//826112 967429
//394496 211145
//478464 101013
//586081 843008
//611584 511773
//736947 421632
//1041467 33024
//963773 600832
//590921 708352
//182139 777984
//96000 965677
//328448 639287
//30679 27392
//118016 747977
//874752 517857
//600832 948055
//464475 118016
//961792 223769
//26880 1034561
//96671 676608
//975616 1036205
//528983 890112
//502528 841015
//213631 310016
//136539 280832
//829293 888064
//445075 139008
//677571 1017088
//886016 202379
//467712 106213
//974615 747264
//274176 810327
//372749 990464
//434944 302673
//526561 264448
//67840 731211
//817363 854784
//271157 945408
//263297 695552
//954112 263221
//1031685 779520
//315648 128899
//653056 396297
//149760 217769
//800369 577792
//622627 448256
//922111 586496
//384831 1036544
//165229 119040
//189184 131211
//784763 769280
//687360 567383
//760576 476147
//974945 32000
//350976 787433
//641199 83200
//432896 529915
//473344 90469
//983296 970457
//57637 782080
//603904 374449
//128999 960256
//599387 853760
//916736 713501
//1000704 110675
//79616 997355
//1014271 281856
//372621 70912
//1013504 341839
//164991 260352
//436805 442624
//1017088 269581
//685743 837376
//712448 716867
//63959 1042688
//824064 195311
//343296 81655
//882432 526005
//71769 550144
//334787 969984
//12032 1007661
//677597 532224
//730945 310528
//461691 487168
//878848 744893
//632077 779520
//304093 212224
//1017105 481536
//912399 191744
//452207 976640
//423271 637184
//259191 83200
//66304 939473
//399209 397056
//519936 556487
//308992 664777
//200103 557824
//365359 865024
//543323 582912
//453605 772352
//898537 871168
//1020757 927488
//894687 492800
//123529 627456
//878336 394769
//274807 546048
//119552 91207
//575232 427529
//415488 933505
//384893 93440
//412403 430848
//82688 413269
//543963 630528
//939776 174253
//281501 261376
//732416 383387
//679871 736000
//570523 571136
//973923 537344
//814825 931584
//40431 153344
//621741 635648
//740097 613120
//121088 978143
//337937 1035008
//892957 653568
//129792 1025495
//915200 905953
//271289 403200
//706816 1038479
//733952 193147
//214272 185241
//686351 691968
//494336 2425
//375361 168704
//584971 664832
//32251 619264
//468047 1008896
//195328 932991
//69983 726784
//919296 106269
//106409 61184
//132864 477173
//372480 418475
//985344 578661
//274176 473573
//636160 576571
//528640 24083
//518983 272640
//382795 546560
//530688 516455
//498944 535821
//24133 346368
//830443 67328
//77665 449792
//434432 862681
//299776 868443
//1033111 340224
//468883 526080
//464640 735277
//18176 712665
//307456 377403
//398357 770816
//843008 1033751
//193245 506112

//// Random 20-bit multipliers for a mask of 0xFFFFF, using ^

//560128 823779
//214016 280661
//726016 169071
//776137 906240
//734208 966197
//478208 175881
//293755 633856
//683809 715776
//345088 747231
//750177 3072
//462401 676864
//787361 130048
//678912 574587
//356771 625664
//1002496 506881
//1041408 780693
//113664 282823
//352843 244736
//472064 881325
//801485 775168
//314368 130723
//881143 539648
//254976 877855
//268369 744448
//979968 653357
//249391 924672
//996352 505401
//727359 730112
//910336 915215
//999647 590848
//337205 545792
//648003 193536
//683008 1016827
//814699 7168
//420864 839957
//128000 844423
//209920 270801
//764807 822272
//1016832 766325
//297984 761045
//852259 621568
//474717 224256
//168621 363520
//223589 111616
//745347 726016
//29696 834659
//128000 280057
//480256 756215
//938689 812032
//488448 852695
//435200 82923
//928768 276761
//156672 571697
//535552 602295

//// Random 20-bit multipliers for a mask of 0xFFFFF, using +

//742001 878080
//459863 394752
//745984 671515
//695808 621729
//163505 1012224
//471539 257536
//130560 1020451
//770335 290304
//339141 278016
//616189 613888
//865792 863093
//45689 437760
//221795 156160
//473600 262405
//645632 420175
//160256 976129
//787747 869888
//978673 718336
//347467 566784
//555385 712192
//459067 220672
//739493 542208
//799857 900608
//741888 807511
//477696 15737
//235289 673280
//676665 1046016
//111147 881152
//25933 426496
//276185 861696
//659097 839168
//242009 29184
//919040 1040691
//851113 682496
//90624 965065
//876443 151040
//781824 72447
//692736 547499
//914944 308931
//802633 616960
//496541 633344
//397739 822784
//977131 46592
//878080 21413
//541629 568832
//1040896 575343
//495104 202605
//167167 1006080
//600479 700928
//136245 980480
//126761 326144
//772608 765007
//699289 602624
//477696 875205
//858181 856576
//40225 282112
//750080 921035
//912896 14531
//671232 830645
//845312 350411
//1019861 584192
//898269 411136
//397824 757895
//927941 6656
//486143 353792
//829952 963137
//1027267 539136
//53441 506368
//717679 429568
//100864 433043
//266031 881152
//147968 84619
//551403 476672
//1013655 804352
//878080 492541
//919040 1011339
//514293 232960
//914944 81711
//425472 191573
//684515 163328
//248320 474525
//572219 830976
//359039 536064
//168448 32601
//969216 675853
//605265 14848
//777728 876713
//151040 367815
//814543 266752
//960000 806887
//925339 1029632
//566885 344576
//941568 1014155
//701952 393151
//645632 592367
//87552 72013
//659968 212389
//418471 733696
//722755 321024
//427315 866816
//796160 306365
//199168 754651
//860141 584192
//808097 156160
//949743 701952
//1022464 475899
//58419 27136
//445952 89011
//642560 746771
//721408 555275
//1013248 730541
//952832 328473
//391553 248320
//606697 541184
//855341 546304
//555520 246229
//416256 576351
//565760 950833
//916429 11776
//693827 674304
//682496 933385
//719759 966144
//374272 611761
//445513 586240
//1019392 754899
//244135 551424
//679219 573952
//352768 294781
//468480 272981
//172205 46592
//561664 150885
//8704 978523
//194048 697431
//487936 480017
//579533 316928